home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / spmmpas.arc / DOS4BH.ASM < prev    next >
Encoding:
Assembly Source File  |  1980-01-01  |  4.0 KB  |  85 lines

  1. code        segment
  2.             assume       cs:code
  3.  
  4. ; FUNCTION called from Turbo Pascal, executes .COM 
  5. ; or .EXE programs using the DOS function 4BH. 
  6. ; Preserves the stack registers, returning the 
  7. ; error code 0 if succesfull or the DOS error code 
  8. ; if the execute fails.
  9.  
  10. ; Pascal declaration: 
  11. ; FUNCTION DOS4BH(VAR PROGRAM_NAME,PARAMETER_STRING):INTEGER
  12.  
  13. arguments   struc                    ; Template to arguments.
  14. save_bp     dw       ?               ; Saved BP register.
  15. ret_adr     dw       ?               ; Return address (near call).
  16. ;-----------------------------------------------------------------
  17. param_str   dd       ?               ; DWORD pointer to param. string
  18. prog_name   dd       ?               ; DWORD pointer to ASCIIZ 
  19.                                      ; program name.
  20. ;---------------------------------------------------------(8 bytes)
  21. arguments   ends
  22.  
  23. dos4BH      proc      near
  24.             jmp       short exec_code
  25. ;---------------------------- LOAD CONTROL BLOCK -----------------
  26. lcb_envir   dw        0              ; Segment address of environment
  27. lcp_ps_o    dw        ?              ; Offset of parameter string.
  28. lcb_ps_s    dw        ?              ; Segment of parameter string.
  29. lcb_fcb1    dd        0              ; Dword pointer to FCB1 
  30.                                      ; (5CH in PSP).
  31. lcb_fcb2    dd        0              ; Dword pointer to FCB2
  32.                                      ; (6CH in PSP).
  33. ;----------------------------- LOCAL VARIABLES -------------------
  34. ss_save     dw        ?              ; Saved stack segment.
  35. sp_save     dw        ?              ; Saved stack pointer.
  36. ;-----------------------------------------------------------------
  37. exec_code:  push      bp
  38.             mov       bp,sp          ; Establish access to arguments.
  39.             push      ds             ; Save the Turbo data segment.
  40.             call      relo1          ; Set BX to relocation 
  41.                                      ; factor: true offset ...
  42. relo1:      pop       bx             ; of reloc1 minus local offset.
  43.             sub       bx,offset relo1
  44.  
  45.             les       di,[bp].param_str  ; Get offset:segment 
  46.                                          ; of parameter string.
  47.             mov       ax,es              
  48.             mov       cs:lcb_ps_s[bx],ax ; Save parameter 
  49.                                          ; string segment ...
  50.             mov       cs:lcp_ps_o[bx],di ; ... and offset in LCB.
  51.             mov       ax,ss              ; Save SS and SP registers
  52.             mov       cs:ss_save[bx],ax
  53.             mov       ax,sp
  54.             mov       cs:sp_save[bx],ax
  55.  
  56.             push      cs                 ; Set up ES:BX as pointer 
  57.                                          ; to the LCB ...
  58.             pop       es
  59.             add       bx,offset lcb_envir
  60.             lds       dx,[bp].prog_name  ; and DS:DX as pointer 
  61.                                          ; to the ASCIIZ ...
  62.             inc       dx                 ; ... program name.
  63.             mov       ax,4B00h      ; DOS EXEC function: al=0, ah=4Bh
  64.             int       21h                ; Let her rip.
  65.  
  66.             sti             ; Disable interrupts while stack messed up
  67.             jc        run_error          ; Successful execution?
  68.             xor       al,al              ; Yes, set error code=0.
  69. run_error:  xor       ah,ah
  70.             call      relo2      ; Recalculate relocation factor ...
  71. relo2:      pop       bx
  72.             sub       bx,offset relo2
  73.             mov       dx,cs:ss_save[bx]  ; ... and restore the stack.
  74.             mov       ss,dx
  75.             mov       dx,cs:sp_save[bx]
  76.             mov       sp,dx
  77.             cli                   ; Interrupts back on ... all done!
  78.  
  79.             pop       ds
  80.             pop       bp
  81.             ret       10          ; Pop arguments & "function result"
  82. dos4BH      endp
  83. code        ends
  84.             end
  85.